<!DOCTYPE html>
<html lang="zh-CN">
<meta charset="utf-8" />
<head>
<title>添加用户 <?php echo $this->config->item('title');?></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet"	href="<?php echo base_url()?>public/css/bootstrap.min.css"/>
<link rel="stylesheet" href="<?php echo base_url()?>public/css/style.css"/>
<link rel="stylesheet" href="<?php echo base_url()?>public/css/bootstrap-select.min.css">
</head>
<body>
	<script src="<?php echo base_url()?>public/js/jquery-2.0.2.min.js"></script>
	<script src="<?php echo base_url()?>public/js/bootstrap.min.js"></script>
	<script src="<?php echo base_url()?>public/js/bootstrap-confirm.js"></script>
	<script src='<?php echo base_url()?>public/js/bootbox.min.js'></script>
	<script src='<?php echo base_url()?>public/js/jquery.form.js'></script>
	<script src='<?php echo base_url()?>public/js/ssi_common.js'></script>
	<script src='<?php echo base_url()?>public/js/bootstrap-select.min.js'></script>
	<script type="text/javascript">
	jQuery(function($) {

		$('.selectpicker').selectpicker();
			
		$('#main_from').ajaxForm({
			dataType:  'json',
			beforeSubmit:  showRequest,
			success:   processJson
		});
	
		function showRequest(formData, jqForm, options) {
		}
	
		function processJson(data) {
			if (data.result==false) {
				bootbox.alert(data.message, function() {
				});
				$('button[type="submit"]').removeClass('disabled');
			}else{
				window.location.href=data.redirect_url;
			}
		}
	});
	function onParent1Changed(){
		 var parent1 = $("#parent1");
		 var parent2 = $("#parent2");
		 parent2.remove();
		 var parent3 = $("#parent3");
		 parent3.remove();
		 var index = $("#parent1").get(0).selectedIndex;
		 if (index == 0) {
		  return;
		 }
		 var parentid = parent1.val();
		 $.getJSON("<?php echo base_url()."index.php/common_dept_manage/get_depts"?>", { dept_id: parentid }, function(json){
		  if (json.length == 0) {
		   return;
		  }
		  $("#parents").append("<select class='span5 form-control' id='parent2' name='dept_id1' onchange='onParent2Changed()'></select>");
		  var parent2 = $("#parent2");
		  parent2.append("<option value='0'>无</option>");
		  for(var i = 0, len = json.length; i<len; ++i){
		   var dept = json[i];
		   parent2.append("<option value=" + dept.dept_id + ">" + dept.dept_name + "</option>");
		  }
		 });
		}
		function onParent2Changed(){
		 var parent2 = $("#parent2");
		 var parent3 = $("#parent3");
		 parent3.remove();
		 var index = $("#parent2").get(0).selectedIndex;
		 if (index == 0) {
		  return;
		 }
		 var parentid = parent2.val();
		 $.getJSON("<?php echo base_url()."index.php/common_dept_manage/get_depts"?>", { dept_id: parentid}, function(json){
		  if (json.length == 0) {
		   return;
		  }
		  $("#parents").append("<select class='span5 form-control' id='parent3' name='dept_id2'></select>");
		  var parent3 = $("#parent3");
		  parent3.append("<option value='0'>无</option>");
		  for(var i = 0, len = json.length; i<len; ++i){
		   var dept = json[i];
		   parent3.append("<option value=" + dept.dept_id + ">" + dept.dept_name + "</option>");
		  }
		 });
		}
	</script>
	
	<div role="navigation" class="navbar navbar-inverse navbar-fixed-top">
		<div class="container">
			<div class="navbar-header">
				<a class="navbar-brand">SSI后台管理系统</a>
			</div>
			<div class="collapse navbar-collapse navbar-right">
				<ul class="nav navbar-nav">
					<li><a href="<?php echo base_url()?>" class="navbar-link">首页</a></li>
					<li><a href="<?php echo base_url()."index.php/common_login_user_set"?>" class="navbar-link">超级管理员</a></li>
					<li><a href="<?php echo base_url()?>index.php/common_login_manage/logout" class="navbar-link">退出</a></li>
				</ul>
			</div>
		</div>
	</div>
	<div class="container">
		<div class="row">
			<div class="col-xs-3">
				<?php echo $user_menu?>
			</div>
			<div class="col-md-9">
				<div class="panel panel-default">
					<div class="panel-heading">添加用户</div>
					<div class="panel-body">
						<form method="post" id="main_from" action="<?php echo base_url()."index.php"?>/common_user_manage/add_user"
							class="form-horizontal">
							<div id="user_name" class="form-group">
								<label for="user_name" class="control-label col-sm-3">用户名</label>
								<div class="col-sm-5">
									<input id="user_name" type="text" name="user_name" required class="form-control">
								</div>
								<span class='help-block'>必填</span>
							</div>
							<div id="password" class="form-group">
								<label for="user_name" class="control-label col-sm-3">密码</label>
								<div class="col-sm-5">
									<input id="password" type="text" name="password" required class="form-control">
								</div>
								<span class='help-block'>必填</span>
							</div>
							<div id="password1" class="form-group">
								<label for="password1" class="control-label col-sm-3">重复密码</label>
								<div class="col-sm-5">
									<input id="password1" type="text" name="password1" required class="form-control">
								</div>
								<span class='help-block'>必填</span>
							</div>
							<div id="name" class="form-group">
								<label for="name" class="control-label col-sm-3">真实姓名</label>
								<div class="col-sm-5">
									<input id="name" type="text" name="name" required class="form-control">
								</div>
								<span class='help-block'>必填</span>
							</div>
							<div id="Parents" class="form-group">
								<label for="parent1" class="control-label col-sm-3">所属部门</label>
								<div id="parents" class="col-sm-5">
									<select id="parent1" name="dept_id"
										onchange="onParent1Changed()" class="form-control">
										<option	value="0">无</option>
										<?php if ($top_depts!=null) {
												foreach ($top_depts as $dept){	?>
										<option value="<?php echo $dept['dept_id']?>"><?php echo $dept['dept_name']?></option>
										<?php 
											}
										}?>
										
									</select>
								</div>
							</div>
							<div id="role_id" class="form-group">
								<label for="role_id" class="control-label col-sm-3">用户角色</label>
								<div class="col-sm-5">
									<select name="role_id[]" multiple id="role_id" data-live-search='true' class="selectpicker form-control">
                                          <?php for ($i = 0; $i < count($role_list); $i++) {?>
                                          <option value="<?php echo $role_list[$i]['role_id']?>"><?php echo $role_list[$i]['role_name']?></option>	
                                          <?php }?>
                                    </select>
								</div>
								<span class='help-block'>必选</span>
							</div>
							<div id="email" class="form-group">
								<label for="email" class="control-label col-sm-3">邮箱地址</label>
								<div class="col-sm-5">
									<input id="email" type="text" name="email"  class="form-control">
								</div>
							</div>
							<div id="sex" class="form-group">
								<label for="sex" class="control-label col-sm-3">性别</label>
								<div class="col-sm-5">
									<p class='form-control-static'>
                                	<input type="radio" value="1" name="sex" id="m" checked="checked"  />男 
                                	<input type="radio" value="0" name="sex" id="f" />女
                                	</p>
								</div>
							</div>
							<div class="form-group">
								<div class="col-sm-offset-3 col-sm-10">
									<button type="button" onclick='from_check_login($("#main_from"),"<?php echo base_url()?>")' class="btn btn-primary">添加</button>
									<a href="javascript:void()" onclick='history.back()' >返回</a>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
<div  class="back-to" id="toolBackTop">
	<a title="返回顶部" onclick="window.scrollTo(0,0);return false;" href="#top" class="back-top">
	返回顶部</a>
	<a title="返回底部" onclick="window.scrollTo(0,document.body.scrollHeight);return false;" href="#bottom" class="back-bottom">
	返回底部</a>
</div>
</body>
</html>
